
clear all
clear mata
clear matrix
set more off
set scheme modern

*set path here*

global rawdata = 
global workingdata = 
global match = 
global temp = 
global table = 


use $workingdata\regdata.dta, clear

*set control variables*

global weather_controls api pre win ssd rhu pre2 win2 ssd2 rhu2
global demo_controls age age2 i.edulist
global demo_controls_cs gender age age2 i.edulist
global fe i.countyid i.year i.month i.week i.endhour

*Table A1 baseline*

reg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls_cs ///
$fe ///
, robust cluster(countyid10)

outreg2 using $table\TableA1.xls ///
,dec(3) keep(tempbin*) adjr2 replace

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

est store word
outreg2 using $table\TableA1.xls ///
,dec(3) keep(tempbin*) adjr2 append

reg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls_cs ///
$fe ///
, robust cluster(countyid10)

outreg2 using $table\TableA1.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

est store math
outreg2 using $table\TableA1.xls ///
,dec(3) keep(tempbin*) adjr2 append

*Figure 2 baseline*

matrix res = J(1,3,.)
matrix rown res = tempbin7
matrix res[1,1] = 0
matrix res[1,2] = 0
matrix res[1,3] = 0

coefplot (word,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
(matrix(res[.,1]),ci((res[.,2] res[.,3])) msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(word,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
,yline(0,lcolor(black)) vertical legend(off) levels(90 95) ///
ytitle("verbal test scores") xtitle("temperature on the interview date") title("A. Verbal test scores: transitory effects")

graph export $table/Figure2a.png, replace

coefplot (math,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
(matrix(res[.,1]),ci((res[.,2] res[.,3])) msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(math,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
,yline(0,lcolor(black)) vertical legend(off) levels(90 95) ///
ytitle("math test scores") xtitle("temperature on the interview date") title("B. Math test scores: transitory effects")

graph export $table/Figure2b.png, replace

*Table A2 AC*

reg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls_cs ///
$fe ///
if AC==1 ///
, robust cluster(countyid10)

est store word_AC
outreg2 using $table\TableA2.xls ///
,dec(3) keep(tempbin*) adjr2 replace

reg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls_cs ///
$fe ///
if AC==0 ///
, robust cluster(countyid10)

est store word_noAC
outreg2 using $table\TableA2.xls ///
,dec(3) keep(tempbin*) adjr2 append

reg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls_cs ///
$fe ///
if AC==1 ///
, robust cluster(countyid10)

est store math_AC
outreg2 using $table\TableA2.xls ///
,dec(3) keep(tempbin*) adjr2 append

reg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls_cs ///
$fe ///
if AC==0 ///
, robust cluster(countyid10)

est store math_noAC
outreg2 using $table\TableA2.xls ///
,dec(3) keep(tempbin*) adjr2 append

*Figure 3 AC*

coefplot (word_noAC,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(O) mcolor(maroon) label("") offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(word_AC,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(T) mcolor(navy) label(with AC) offset(-0.2) ///
ciopts(recast(rcap) lcolor(navy navy))) ///
(matrix(res[.,1]),ci((res[.,2] res[.,3])) label("") msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(word_noAC,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(O) mcolor(maroon) label(without AC) offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(word_AC,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(T) mcolor(navy) label("") offset(-0.2)  ///
ciopts(recast(rcap) lcolor(navy navy))) ///
,yline(0,lcolor(black)) vertical legend(row(1) pos(6)) levels(90 95) ///
ytitle("verbal test scores") xtitle("temperature on the interview date") title("A. Verbal test scores") ///
ysize(4) xsize(8)

graph export $table/Figure3a.png, replace

coefplot (math_noAC,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(O) mcolor(maroon) label("") offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(math_AC,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(T) mcolor(navy) label(with AC) offset(-0.2) ///
ciopts(recast(rcap) lcolor(navy navy))) ///
(matrix(res[.,1]),ci((res[.,2] res[.,3])) label("") msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(math_noAC,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(O) mcolor(maroon) label(without AC) offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(math_AC,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(T) mcolor(navy) label("") offset(-0.2)  ///
ciopts(recast(rcap) lcolor(navy navy))) ///
,yline(0,lcolor(black)) vertical legend(row(1) pos(6)) levels(90 95) ///
ytitle("math test scores") xtitle("temperature on the interview date") title("B. Math test scores") ///
ysize(4) xsize(8)

graph export $table/Figure3b.png, replace

*Table A3 region*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if temp_group==1 ///
, fe robust cluster(countyid10)

est store word_cold
outreg2 using $table\TableA3.xls ///
,dec(3) keep(tempbin*) adjr2 replace

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if temp_group==0 ///
, fe robust cluster(countyid10)

est store word_hot
outreg2 using $table\TableA3.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if temp_group==1 ///
, fe robust cluster(countyid10)

est store math_cold
outreg2 using $table\TableA3.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if temp_group==0 ///
, fe robust cluster(countyid10)

est store math_hot
outreg2 using $table\TableA3.xls ///
,dec(3) keep(tempbin*) adjr2 append

*Figure 4 region*

coefplot (word_hot,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(O) mcolor(maroon) label("") offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(word_cold,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(T) mcolor(navy) label(cool) offset(-0.2) ///
ciopts(recast(rcap) lcolor(navy navy))) ///
(matrix(res[.,1]),ci((res[.,2] res[.,3])) label("") msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(word_hot,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(O) mcolor(maroon) label(hot) offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(word_cold,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(T) mcolor(navy) label("") offset(-0.2)  ///
ciopts(recast(rcap) lcolor(navy navy))) ///
,yline(0,lcolor(black)) vertical legend(row(1) pos(6)) levels(90 95) ///
ytitle("verbal test scores") xtitle("temperature on the interview date") title("A. Verbal test scores") ///
ysize(4) xsize(8)

graph export $table/Figure4a.png, replace

coefplot (math_hot,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(O) mcolor(maroon) label("") offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(math_cold,keep(tempbin1 tempbin2 tempbin3 tempbin4 tempbin5 tempbin6) msymbol(T) mcolor(navy) label(cool) offset(-0.2) ///
ciopts(recast(rcap) lcolor(navy navy))) ///
(matrix(res[.,1]),ci((res[.,2] res[.,3])) label("") msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(math_hot,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(O) mcolor(maroon) label(hot) offset(0.2) ///
ciopts(recast(rcap) lcolor(maroon maroon))) ///
(math_cold,keep(tempbin8 tempbin9 tempbin10 tempbin11 tempbin12) msymbol(T) mcolor(navy) label("") offset(-0.2)  ///
ciopts(recast(rcap) lcolor(navy navy))) ///
,yline(0,lcolor(black)) vertical legend(row(1) pos(6)) levels(90 95) ///
ytitle("math test scores") xtitle("temperature on the interview date") title("B. Math test scores") ///
ysize(4) xsize(8)

graph export $table/Figure4b.png, replace

*Figure 5 stratification*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if age_group==1 ///
, fe robust cluster(countyid10)

est store word_lage

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if age_group==2 ///
, fe robust cluster(countyid10)

est store word_mage

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if age_group==3 ///
, fe robust cluster(countyid10)

est store word_hage

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if age_group==1 ///
, fe robust cluster(countyid10)

est store math_lage

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if age_group==2 ///
, fe robust cluster(countyid10)

est store math_mage

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if age_group==3 ///
, fe robust cluster(countyid10)

est store math_hage

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if edu_group==1 ///
, fe robust cluster(countyid10)

est store word_ledu

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if edu_group==2 ///
, fe robust cluster(countyid10)

est store word_hedu

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if edu_group==1 ///
, fe robust cluster(countyid10)

est store math_ledu

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
if edu_group==2 ///
, fe robust cluster(countyid10)

est store math_hedu

coefplot (word_lage, label(age 30 or below) msymbol(T) mcolor(navy) offset(-0.3)) (word_mage, label(age 31-59) msymbol(S) mcolor(maroon) offset(0)) (word_hage, label(age 60 or above) msymbol(Oh) mcolor(green) offset(0.3)), bylabel(Verbal test scores) ///
      || (math_lage)                     (math_mage)                               (math_hage), bylabel(Math test scores) ///
      ||,keep(tempbin12) grid(between) vertical legend(row(1)) yline(0,lcolor(black)) ciopts(recast(rcap)) ///
levels(90 95) byopts(yrescale title(A. Age cohort)) ///
mlabel format(%9.3f) mlabcolor(black) mlabposition(3) mlabgap(*2) ///
saving("$temp/age", replace)

coefplot (word_ledu, label(high school or below) msymbol(T) mcolor(navy) offset(-0.2)) (word_hedu, label(college or above) msymbol(Oh) mcolor(maroon) offset(0.2)), bylabel(Verbal test scores) ///
      || (math_ledu)                                                                      (math_hedu), bylabel(Math test scores) ///
      ||,keep(tempbin12) grid(between) vertical legend(row(1)) yline(0,lcolor(black)) ciopts(recast(rcap)) ///
levels(90 95) byopts(yrescale title(B. Education level)) ///
mlabel format(%9.3f) mlabcolor(black) mlabposition(3) mlabgap(*2) ///
saving("$temp/edu", replace)

gr combine "$temp/age" "$temp/edu" ///
   , col(1) ysize(12) xsize(12)
graph export "$table/Figure5.png", replace

*Figure A6 cumulative effects*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
tempbin1_sum_30-tempbin6_sum_30 tempbin8_sum_30-tempbin12_sum_30 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

est store word_sum_30

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
tempbin1_sum_30-tempbin6_sum_30 tempbin8_sum_30-tempbin12_sum_30 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

est store math_sum_30

matrix res_sum_30 = J(1,3,.)
matrix rown res_sum_30 = tempbin7_sum_30
matrix res_sum_30[1,1] = 0
matrix res_sum_30[1,2] = 0
matrix res_sum_30[1,3] = 0

coefplot (word_sum_30,keep(tempbin1_sum_30 tempbin2_sum_30 tempbin3_sum_30 tempbin4_sum_30 tempbin5_sum_30 tempbin6_sum_30) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
(matrix(res_sum_30[.,1]),ci((res_sum_30[.,2] res_sum_30[.,3])) msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(word_sum_30,keep(tempbin8_sum_30 tempbin9_sum_30 tempbin10_sum_30 tempbin11_sum_30 tempbin12_sum_30) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
,yline(0,lcolor(black)) vertical legend(off) levels(90 95) ///
ytitle("verbal test scores") xtitle("the number of days in the past 30 days") title("A. Verbal test scores: cumulative effects in the past 30 days") ///
mlabel format(%9.3f) mlabcolor(black) mlabposition(3) mlabgap(*1) ///
saving("$temp/word_sum_30", replace)

coefplot (math_sum_30,keep(tempbin1_sum_30 tempbin2_sum_30 tempbin3_sum_30 tempbin4_sum_30 tempbin5_sum_30 tempbin6_sum_30) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
(matrix(res_sum_30[.,1]),ci((res_sum_30[.,2] res_sum_30[.,3])) msymbol(O) mcolor(black) ciopts(recast(rcap))) ///
(math_sum_30,keep(tempbin8_sum_30 tempbin9_sum_30 tempbin10_sum_30 tempbin11_sum_30 tempbin12_sum_30) msymbol(O) mcolor(black) offset(0) ///
ciopts(recast(rcap) lcolor(black black))) ///
,yline(0,lcolor(black)) vertical legend(off) levels(90 95) ///
ytitle("math test scores") xtitle("the number of days in the past 30 days") title("B. Math test scores: cumulative effects in the past 30 days") ///
mlabel format(%9.3f) mlabcolor(black) mlabposition(3) mlabgap(*1) ///
saving("$temp/math_sum_30", replace)

gr combine "$temp/word_sum_30"  "$temp/math_sum_30" ///
   , col(1) ysize(10) xsize(12)
graph export "$table/FigureA6.png", replace

*Table A4 placebo tests and behavioral channels*

*placebo*

xtreg wordtest ///
tempbin1_F1-tempbin6_F1 tempbin8_F1-tempbin12_F1 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA4.xls ///
,dec(3) keep(tempbin*) adjr2 replace

xtreg mathtest ///
tempbin1_F1-tempbin6_F1 tempbin8_F1-tempbin12_F1 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA4.xls ///
,dec(3) keep(tempbin*) adjr2 append

*cooperation and impatience*

xtreg cooperation ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA4.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg impatience ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA4.xls ///
,dec(3) keep(tempbin*) adjr2 append

*iwtime*

xtreg iwtime ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA4.xls ///
,dec(3) keep(tempbin*) adjr2 append

*Table A5 robustness check1*

*adding county specific trend and calendar date FE*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
i.countyid##c.t i.day i.year i.month i.week i.endhour ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 replace

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
i.countyid##c.t i.day i.year i.month i.week i.endhour ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

*adding iwtime*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls iwtime ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

*removing api*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
pre win ssd rhu pre2 win2 ssd2 rhu2 ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
pre win ssd rhu pre2 win2 ssd2 rhu2 ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

*adding outdoor*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls outdoor ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls outdoor ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA5.xls ///
,dec(3) keep(tempbin*) adjr2 append

*Table A6 robustness check2*

*log*

xtreg logwordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 replace

xtreg logmathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

*non-school*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if non_school==1 ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if non_school==1 ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

*non-migrant*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if non_migrant==1 ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if non_migrant==1 ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

*excluding ozone dominated days*

xtreg wordtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if pollutant!="o3" ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

xtreg mathtest ///
tempbin1-tempbin6 tempbin8-tempbin12 ///
$weather_controls ///
$demo_controls ///
$fe ///
if pollutant!="o3" ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA6.xls ///
,dec(3) keep(tempbin*) adjr2 append

*Table A7 effects of consecutive heat waves*

xtreg wordtest ///
lastcontinueday ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA7.xls ///
,dec(3) keep(last*) adjr2 replace

xtreg mathtest ///
lastcontinueday ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA7.xls ///
,dec(3) keep(last*) adjr2 append

xtreg wordtest ///
last30d ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA7.xls ///
,dec(3) keep(last*) adjr2 append

xtreg mathtest ///
last30d ///
$weather_controls ///
$demo_controls ///
$fe ///
, fe robust cluster(countyid10)

outreg2 using $table\TableA7.xls ///
,dec(3) keep(last*) adjr2 append


*Figure 1 distribution of daily mean temperature on the test date*

use $workingdata\regdata.dta, clear

sum tempbin1-tempbin12

*Table 1 summary statistics*

use $workingdata\regdata.dta, clear

sum wordtest mathtest gender age eduy ///
temp tempbin12 ///
api pre win ssd rhu

sum wordtest mathtest gender age eduy ///
temp tempbin12 ///
api pre win ssd rhu if tempbin12==1

sum wordtest mathtest gender age eduy ///
temp tempbin12 ///
api pre win ssd rhu if tempbin12==0

foreach var of varlist wordtest mathtest gender age eduy temp tempbin12 api pre win ssd rhu {
ttest `var', by(tempbin12)
}

*Figure A2 histogram of mean temperature (°C) on the test date*

use $workingdata\regdata.dta, clear

histogram temp

*Figure A3 distribution of interview months in 2010, 2014 and 2018*

use $workingdata\regdata.dta, clear

tab month

*Figure A4 Relationship between cognitive test scores and mean values of education years*

use $workingdata\regdata.dta, clear

cumul wordtest,generate(wordtestrr) equal

collapse (mean) eduy wordtestrr,by(wordtest)

reg eduy wordtest

use $workingdata\regdata.dta, clear

cumul mathtest,generate(mathtestrr) equal

collapse (mean) eduy mathtestrr,by(mathtest)

reg eduy mathtest

*Figure A5 distribution of mean temperature (°C) in the past 30 days*

use $workingdata\regdata.dta, clear

sum tempbin1_sum_30-tempbin12_sum_30
